package com.kaifamiao.month03.day0329;

import java.util.Arrays;

public class ArrayUtil {

    public static int misMatch(int[] a, int[] b) {
        int len = Math.min(a.length, b.length);
        for(int i = 0; i < len; i ++){
            if(a[i] != b[i])
                return i;
        }
        return a.length == b.length ? -1 : len;
    }

    /**
     * 删除指定位置的元素
     * @param arr 需要删除元素的数组
     * @param index 需要删除的元素下标
     */
    public static int[] deleteElement(int[] arr, int index){
        int[] newArr = new int[arr.length - 1];
        newArr = Arrays.copyOf(arr,index);
        for (int i = index + 1; i < arr.length; i ++) {
            newArr[i - 1] = arr[i];
        }
        return newArr;
    }

    public static void main(String[] args) {
        int[] a = { 1, 2, 3};
        int[] b = { 1, 2, 3, 4, 5};
        System.out.println(misMatch(a,b));
        a = deleteElement(a,2);
        for (int i : a) {
            System.out.print(i);
        }
    }
}
